#include "userinforwidget.h"
#include <QGridLayout>
#include <QPushButton>
#include <QFont>
#include <QFontDatabase>

UserInforWidget::UserInforWidget(QWidget *parent)
    : QDialog(parent)
{
    // 设置窗口属性
    this->setAttribute(Qt::WA_DeleteOnClose);
    this->setWindowTitle("用户信息");
    this->setWindowIcon(QIcon(":/Resources/windowIcon.png"));
    this->setFixedSize(500, 320);
    this->setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #f5f7fa, stop:1 #c3cfe2);");

    // 创建主布局
    QGridLayout *layout = new QGridLayout();
    layout->setContentsMargins(30, 20, 30, 25);
    layout->setHorizontalSpacing(15);
    layout->setVerticalSpacing(12);
    this->setLayout(layout);

    // 尺寸定义
    QSize flagSize(60, 35);
    QSize labelSize(220, 35);
    QSize buttonSize(120, 35);

    // 头像区域
    avatorwidget = new QPushButton();
    avatorwidget->setFixedSize(85, 85);
    avatorwidget->setIcon(QIcon(":/Resources/avator1.jpg"));
    avatorwidget->setIconSize(QSize(85, 85));
    avatorwidget->setStyleSheet(
        "QPushButton {"
        "    border: 3px solid #ffffff;"
        "    border-radius: 42px;"
        "    background: transparent;"
        "}"
        "QPushButton:hover {"
        "    border-color: #4CAF50;"
        "    background-color: rgba(76, 175, 80, 0.1);"
        "}");

    // 信息标签样式
    QString labelStyle =
        "QLabel {"
        "    background-color: rgba(255,255,255,150);"
        "    border: 1px solid #e0e0e0;"
        "    border-radius: 8px;"
        "    padding: 5px 10px;"
        "    color: #333333;"
        "    font-size: 14px;"
        "}";

    QString flagStyle =
        "QLabel {"
        "    color: #555555;"
        "    font-weight: 600;"
        "    font-size: 14px;"
        "    background: transparent;"
        "    border: none;"
        "}";

    // 序号区域
    numberflag = new QLabel();
    numberflag->setFixedSize(flagSize);
    numberflag->setText("序号");
    numberflag->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    numberflag->setStyleSheet(flagStyle);

    numberlabel = new QLabel();
    numberlabel->setFixedSize(labelSize);
    numberlabel->setText(this->number);
    numberlabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    numberlabel->setStyleSheet(labelStyle);

    // 昵称区域
    nameflag = new QLabel();
    nameflag->setText("昵称");
    nameflag->setFixedSize(flagSize);
    nameflag->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    nameflag->setStyleSheet(flagStyle);

    namelabel = new QLabel();
    namelabel->setFixedSize(labelSize);
    namelabel->setText(this->name);
    namelabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    namelabel->setStyleSheet(labelStyle);

    // 电话区域
    telephoneflag = new QLabel();
    telephoneflag->setText("电话");
    telephoneflag->setFixedSize(flagSize);
    telephoneflag->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    telephoneflag->setStyleSheet(flagStyle);

    telephonelabel = new QLabel();
    telephonelabel->setFixedSize(labelSize);
    telephonelabel->setText(this->telephone);
    telephonelabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    telephonelabel->setStyleSheet(labelStyle);

    // 按钮样式 - 修正后的版本
    QString buttonStyle =
        "QPushButton {"
        "    background-color: #4CAF50;"
        "    border: none;"
        "    border-radius: 6px;"
        "    color: white;"
        "    font-weight: 600;"
        "    font-size: 13px;"
        "    padding: 8px 0px;"
        "}"
        "QPushButton:hover {"
        "    background-color: #45a049;"
        "    border: 1px solid #388E3C;"
        "}"
        "QPushButton:pressed {"
        "    background-color: #3d8b40;"
        "    padding: 9px 0px 7px 0px;"  // 模拟按下效果
        "}";

    QString deleteButtonStyle =
        "QPushButton {"
        "    background-color: #f44336;"
        "    border: none;"
        "    border-radius: 6px;"
        "    color: white;"
        "    font-weight: 600;"
        "    font-size: 13px;"
        "    padding: 8px 0px;"
        "}"
        "QPushButton:hover {"
        "    background-color: #da190b;"
        "    border: 1px solid #B71C1C;"
        "}"
        "QPushButton:pressed {"
        "    background-color: #c62828;"
        "    padding: 9px 0px 7px 0px;"  // 模拟按下效果
        "}";

    // 功能按钮
    applybtn = new QPushButton();
    applybtn->setText("申请好友");
    applybtn->setFixedSize(buttonSize);
    applybtn->setStyleSheet(buttonStyle);

    sendbtn = new QPushButton();
    sendbtn->setText("发送消息");
    sendbtn->setFixedSize(buttonSize);
    sendbtn->setStyleSheet(buttonStyle);

    deletebtn = new QPushButton();
    deletebtn->setText("删除好友");
    deletebtn->setFixedSize(buttonSize);
    deletebtn->setStyleSheet(deleteButtonStyle);

    // 添加到布局
    layout->addWidget(avatorwidget, 0, 0, 3, 1, Qt::AlignCenter);
    layout->addWidget(numberflag, 0, 1, 1, 1);
    layout->addWidget(numberlabel, 0, 2, 1, 1);
    layout->addWidget(nameflag, 1, 1, 1, 1);
    layout->addWidget(namelabel, 1, 2, 1, 1);
    layout->addWidget(telephoneflag, 2, 1, 1, 1);
    layout->addWidget(telephonelabel, 2, 2, 1, 1);

    // 按钮布局
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget(applybtn);
    buttonLayout->addWidget(sendbtn);
    buttonLayout->addWidget(deletebtn);
    buttonLayout->setSpacing(10);
    buttonLayout->setContentsMargins(0, 10, 0, 0);

    layout->addLayout(buttonLayout, 3, 0, 1, 3);
}
